<?php 
	Class Restaurant extends CI_Controller{
		public function __construct(){
			parent::__construct();
			$this->load->model("model_restaurant");
			$this->load->model("model_restaurantbanner");
			$this->load->model("model_restaurantreview");
			$this->load->model("model_package");
			$this->load->model("model_activity");
			$this->load->model("model_flight");
			$this->load->model("model_car");
			$this->load->model("model_guild");
		}
		public function searchresult(){
			if(isset($_GET['provide'])){
				$data['data']=$this->model_restaurant->listall_bygetprovide_orname('provide',$_GET['provide'],10,0);				
				$data['total']=$this->model_restaurant->listall_bygetprovide_orname('provide',$_GET['provide'],10000000000,0);		
				if(count($data['total'])>0){
					foreach($data['total'] as $item){
						$data["listbanner"][]=$this->model_restaurantbanner->gettopbanner_search($item['id']);
					}
				}else $data["listbanner"]=NULL;
				
			}else if(isset($_GET['name'])){
				$data['data']=$this->model_restaurant->listall_bygetprovide_orname('name',$_GET['name'],10,0);				
				$data['total']=$this->model_restaurant->listall_bygetprovide_orname('name',$_GET['name'],10000000000,0);		
			}
			
			foreach($data["data"] as &$list){		
				$list["datareview"]=$this->model_restaurantreview->getallbyrestaurantid($list["id"]);			
				if(count($list["datareview"])>0){
					$totalmarkreview=0;	
					foreach($list["datareview"] as $listroom){
						$totalmarkreview+=$listroom["mark"];
					}	
				$list["star"]=floor($totalmarkreview/count($list["datareview"]));}					
				else $list["star"]=0;
			}

			$data['listname_restaurant']=$this->model_restaurant->listall_name();
			
			$data["template"]="restaurant/searchresult";
			$this->load->view("layout",$data);
		}
		public function detail($idrestaurant){
			$data['idrestaurant']=intval($idrestaurant);
			if(isset($idrestaurant)){
				$data['data']=$this->model_restaurant->getdata(intval($idrestaurant));	
				$data['banner']=$this->model_restaurantbanner->getallbyrestaurantid(intval($idrestaurant));
			}
			
			$data["restaurant"]=$this->model_restaurant->gettopByprovide_status($data['data']['provide'],0,6,0);
			$data["activities"]=$this->model_activity->gettopByprovide_status($data['data']['provide'],0,6,0);
			$data["package"]=$this->model_package->gettopByprovide_status($data['data']['provide'],0,6,0);
			$data["flight"]=$this->model_flight->gettopByprovide_status($data['data']['provide'],0,6,0);
			$data["car"]=$this->model_car->gettopByprovide_status($data['data']['provide'],0,3,0);
			$data["guide"]=$this->model_guild->gettopByprovide_status($data['data']['provide'],0,3,0);
			$data['listname_restaurant']=$this->model_restaurant->listall_name();
			
			$data["template"]="restaurant/restaurant_detail";
			$this->load->view("layout",$data);
		}
		
		public function restaurantinmyanmar(){
			$data['yangon']=$this->model_restaurant->countbyprovide('yangon');
			$data['mandalay']=$this->model_restaurant->countbyprovide('mandalay');
			$data['inle']=$this->model_restaurant->countbyprovide('inle');
			$data['bagan']=$this->model_restaurant->countbyprovide('bagan');
			$data['listname_restaurant']=$this->model_restaurant->listall_name();
			$data["template"]="restaurant/myanmar";
			$this->load->view("layout",$data);
		}
	}
?>